package com.cleaningcloud.cld.controller;

import java.util.List;

import com.cleaningcloud.cld.domain.dto.CldAttendanceDto;
import com.cleaningcloud.cld.domain.vo.CldAttendanceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import com.cleaningcloud.cld.domain.CldAttendance;
import com.cleaningcloud.cld.service.ICldAttendanceService;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.utils.poi.ExcelUtil;
import com.cleaningcloud.common.core.web.page.TableDataInfo;

/**
 * 考勤打卡Controller
 * 
 * @author cleaningcloud
 * @date 2024-11-08
 */
@RestController
@RequestMapping("/attendance")
public class CldAttendanceController extends BaseController
{
    @Autowired
    private ICldAttendanceService cldAttendanceService;

    /**
     * 查询考勤打卡列表
     */
    @RequiresPermissions("cld:attendance:list")
    @GetMapping("/list")
    public TableDataInfo list(CldAttendanceDto cldAttendance)
    {
        startPage();
        List<CldAttendanceVo> list = cldAttendanceService.selectCldAttendanceList(cldAttendance);
        return getDataTable(list);
    }


    /**
     * 项目分类 - 查看考勤列表
     */
    @RequiresPermissions("cld:attendance:list")
    @GetMapping("/projectClassificationList")
    public TableDataInfo projectClassificationList(CldAttendanceDto cldAttendance)
    {
        startPage();
        List<CldAttendanceVo> list = cldAttendanceService.selectProjectClassificationList(cldAttendance);
        return getDataTable(list);
    }


    /**
     * 考勤统计 - 查看考勤列表
     */
    @RequiresPermissions("cld:attendance:list")
    @GetMapping("/selectAttendanceStatisticsList")
    public TableDataInfo selectAttendanceStatisticsList(CldAttendanceDto cldAttendance)
    {
        startPage();
        List<CldAttendanceVo> list = cldAttendanceService.selectAttendanceStatisticsList(cldAttendance);
        return getDataTable(list);
    }



    /**
     * 获取考勤打卡详细信息
     */
    @RequiresPermissions("cld:attendance:query")
    @GetMapping(value = "/{attendanceId}")
    public AjaxResult getInfo(@PathVariable("attendanceId") Long attendanceId)
    {
        return success(cldAttendanceService.selectCldAttendanceByAttendanceId(attendanceId));
    }

    /**
     * 新增考勤打卡
     */
    @RequiresPermissions("cld:attendance:add")
    @Log(title = "考勤打卡", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CldAttendance cldAttendance)
    {
        return toAjax(cldAttendanceService.insertCldAttendance(cldAttendance));
    }

    /**
     * 修改考勤打卡
     */
    @RequiresPermissions("cld:attendance:edit")
    @Log(title = "考勤打卡", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CldAttendance cldAttendance)
    {
        return toAjax(cldAttendanceService.updateCldAttendance(cldAttendance));
    }

    @PutMapping("/batchUpdateAttendance")
    public AjaxResult batchUpdateAttendance(@RequestBody List<CldAttendance> list)
    {
        return toAjax(cldAttendanceService.batchUpdateAttendance(list));
    }

    /**
     * 删除考勤打卡
     */
    @RequiresPermissions("cld:attendance:remove")
    @Log(title = "考勤打卡", businessType = BusinessType.DELETE)
	@DeleteMapping("/{attendanceIds}")
    public AjaxResult remove(@PathVariable Long[] attendanceIds)
    {
        return toAjax(cldAttendanceService.deleteCldAttendanceByAttendanceIds(attendanceIds));
    }


    /**
     * 列表查看项目排休一览
     */
    @RequiresPermissions("cld:attendance:query")
    @GetMapping(value = "/getTableCalendarList")
    public AjaxResult getTableCalendarList(CldAttendanceDto cldAttendanceDto)
    {
        return success(cldAttendanceService.getTableCalendarList(cldAttendanceDto));
    }

    /**
     * 日历查看员工排休一览
     */
    @RequiresPermissions("cld:attendance:query")
    @GetMapping(value = "/getCalendarByStaffId")
    public AjaxResult getCalendarByStaffId(CldAttendanceDto cldAttendanceDto)
    {
        return success(cldAttendanceService.getCalendarByStaffId(cldAttendanceDto));
    }
}
